public class ReverseBits {

    // you need treat n as an unsigned value
    public static int reverseBits(int n) {

        if(n==0) return 0;

        int result = 0;

        //System.out.println(Integer.toBinaryString(n));
        //System.out.println(Long.toBinaryString(n));

        for(int i=0;i < 32;i++){
            result |= ((n & (1<<(31-i)))>>>(31-i))<<i;
            //           System.out.println((n & (1<<(31-i)))>>>(31 - i));
        }

        
        //System.out.println(Integer.toBinaryString(result));
        return result;
    }
    
    public static void main(String[] args) {
        System.out.println(reverseBits(Integer.parseUnsignedInt("2147483648",10)));
    }
}